package com.hh.game.service.hall.service.impl;

import com.hh.game.service.hall.domain.User;
import com.hh.game.service.hall.service.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@DubboService(version = "1.0.0" ,stub = "com.hh.game.service.hall.service.UserServiceStub" ,delay = -1)
public class UserServiceImpl implements UserService {
    private Logger log = LoggerFactory.getLogger(UserServiceImpl.class);

//    @Autowired
//    private DefaultMQProducer producer;
//
//    private NoticeProducer notice;
//
//    @PostConstruct
//    public void setProducer() {
//        try {
//            producer.start();
//            notice = new NoticeProducerImpl(producer);
//        } catch (Exception e) {
//            log.error("start mq producer error :" + e.getMessage(), e);
//        }
//    }

    @Override
    public User update(User user) {
        user.setId(user.getId() + 1);
        user.setName(user.getName() + "_1");
        return user;
    }

    @Override
    public String echoName(String name, User user, int id) {
        return id + ":" + name + "@" + user;
    }

    @Override
    public String echoName(String name, User user) {
        return name + "@" + user;
    }

    @Override
    public void noticeUser(int userId, String msg) {
        try {
//            notice.notice(userId, "notice.route.test", msg);
        } catch (Exception e) {
            log.error("notice user [" + userId + "] error : " + e.getMessage(), e);
        }
    }

    @Override
    public void broadcastUser(String msg) {
        try {
//            notice.broadcast("notice.route.test", msg);
        } catch (Exception e) {
            log.error("broadcast user error : " + e.getMessage(), e);
        }
    }
}
